package org.jeecg.modules.minqing.job;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.minqing.entity.Project;
import org.jeecg.modules.minqing.entity.ResourceManage;
import org.jeecg.modules.minqing.service.IProjectService;
import org.jeecg.modules.minqing.service.IResourceManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
@Configuration
@EnableScheduling
@EnableAsync
public class ProjectScheduleTask {
    @Autowired
    @SuppressWarnings("all")
    private IProjectService projectService;
    @Autowired
    @SuppressWarnings("all")
    private IResourceManageService resourceManageService;
    @Async
    @Scheduled(cron = "0 0/5 * * * ? ") //5分执行一次
    public void updateResourceManage(){
        log.info("更新资源分布 start");
        List<Project> projectList = projectService.list();
        List<ResourceManage> resourceManageList = new ArrayList<>();
        for (Project project:projectList){
            ResourceManage resource = new ResourceManage();
            resource.setId(project.getId());
            resource.setTitle(project.getProjectName());
            resource.setDepartment(project.getDepartment());
            resource.setIndustryType(project.getIndustryType());
            resource.setCoordinateX(project.getCoordinateX());
            resource.setCoordinateY(project.getCoordinateY());
            resource.setContent(project.getText());
            resource.setPic(project.getImg());
            resourceManageList.add(resource);
        }
        resourceManageService.updateWholeTable(resourceManageList);
        log.info("更新资源分布 end");
    }

}
